--------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/Wei/Dropbox/Fertility/Results/UHS_data.log
  log type:  text
 opened on:  28 Apr 2020, 11:54:50

. 
. ***** Section UHS *****
. use "$path1/2002p",clear 

. keep hcode dcode prov pnum  a* 

. gen year = 2002

. save "$path2/2002_data_1",replace 
(note: file /Users/Wei/Dropbox/Fertility/Workingdata/2002_data_1.dta not found)
file /Users/Wei/Dropbox/Fertility/Workingdata/2002_data_1.dta saved

. use "$path1/2002h",clear 

. keep dcode hcode qs d*  e* f? f?? f??? b*

. merge 1:m dcode hcode using "$path2/2002_data_1"

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                           109,326  (_merge==3)
    -----------------------------------------

. drop _merge 

. save "$path2/2002_data",replace 
(note: file /Users/Wei/Dropbox/Fertility/Workingdata/2002_data.dta not found)
file /Users/Wei/Dropbox/Fertility/Workingdata/2002_data.dta saved

. cap erase "$path2/2002_data_1.dta"

. 
. use "$path1/2003p",clear 

. keep hcode dcode prov hnum  a*

. gen year = 2003 

. save "$path2/2003_data_1",replace 
(note: file /Users/Wei/Dropbox/Fertility/Workingdata/2003_data_1.dta not found)
file /Users/Wei/Dropbox/Fertility/Workingdata/2003_data_1.dta saved

. use "$path1/2003h",clear 

. keep dcode hcode qs d*  e* f? f?? f???  b*

. merge 1:m dcode hcode using "$path2/2003_data_1"

    Result                           # of obs.
    -----------------------------------------
    not matched                           400
        from master                       400  (_merge==1)
        from using                          0  (_merge==2)

    matched                           120,845  (_merge==3)
    -----------------------------------------

. drop _merge 

. save "$path2/2003_data",replace 
(note: file /Users/Wei/Dropbox/Fertility/Workingdata/2003_data.dta not found)
file /Users/Wei/Dropbox/Fertility/Workingdata/2003_data.dta saved

. cap erase "$path2/2003_data_1.dta"

. 
. use "$path1/2004p",clear 

. keep hcode dcode prov hnum  a*

. 
. gen year = 2004

. save "$path2/2004_data_1",replace 
(note: file /Users/Wei/Dropbox/Fertility/Workingdata/2004_data_1.dta not found)
file /Users/Wei/Dropbox/Fertility/Workingdata/2004_data_1.dta saved

. use "$path1/2004h",clear 

. keep dcode hcode qs d*  e* f? f?? f???  b*

. merge 1:m dcode hcode using "$path2/2004_data_1"

    Result                           # of obs.
    -----------------------------------------
    not matched                             1
        from master                         1  (_merge==1)
        from using                          0  (_merge==2)

    matched                           127,157  (_merge==3)
    -----------------------------------------

. drop _merge 

. save "$path2/2004_data",replace 
(note: file /Users/Wei/Dropbox/Fertility/Workingdata/2004_data.dta not found)
file /Users/Wei/Dropbox/Fertility/Workingdata/2004_data.dta saved

. cap erase "$path2/2004_data_1.dta"

. 
. use "$path1/2005p",clear 

. keep hcode dcode prov hnum  a*

. 
. gen year = 2005

. save "$path2/2005_data_1",replace 
(note: file /Users/Wei/Dropbox/Fertility/Workingdata/2005_data_1.dta not found)
file /Users/Wei/Dropbox/Fertility/Workingdata/2005_data_1.dta saved

. use "$path1/2005h",clear 

. keep dcode hcode qs d*  e* f? f?? f???  b*

. merge 1:m dcode hcode using "$path2/2005_data_1"

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                           132,453  (_merge==3)
    -----------------------------------------

. drop _merge 

. save "$path2/2005_data",replace 
(note: file /Users/Wei/Dropbox/Fertility/Workingdata/2005_data.dta not found)
file /Users/Wei/Dropbox/Fertility/Workingdata/2005_data.dta saved

. cap erase "$path2/2005_data_1.dta"

. 
. use "$path1/2006p",clear 

. keep hcode dcode prov hnum  a*

. 
. gen year = 2006 

. save "$path2/2006_data_1",replace 
(note: file /Users/Wei/Dropbox/Fertility/Workingdata/2006_data_1.dta not found)
file /Users/Wei/Dropbox/Fertility/Workingdata/2006_data_1.dta saved

. use "$path1/2006h",clear 

. keep dcode hcode qs d*  e* f? f?? f???  b*

. merge 1:m dcode hcode using "$path2/2006_data_1"

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                           131,690  (_merge==3)
    -----------------------------------------

. drop _merge 

. save "$path2/2006_data",replace 
(note: file /Users/Wei/Dropbox/Fertility/Workingdata/2006_data.dta not found)
file /Users/Wei/Dropbox/Fertility/Workingdata/2006_data.dta saved

. cap erase "$path2/2006_data_1.dta"

. 
. 
. use "$path1/2007p",clear 

. keep hcode dcode prov pnum  a*

. 
. replace a7 = (2007-int(a7/100)) 
(131,616 real changes made)

. gen year = 2007 

. save "$path2/2007_data_1",replace 
(note: file /Users/Wei/Dropbox/Fertility/Workingdata/2007_data_1.dta not found)
file /Users/Wei/Dropbox/Fertility/Workingdata/2007_data_1.dta saved

. use "$path1/2007h",clear 

. keep dcode hcode qs d*  e* f? f?? f???  b*

. merge 1:m dcode hcode using "$path2/2007_data_1"

    Result                           # of obs.
    -----------------------------------------
    not matched                         2,360
        from master                         0  (_merge==1)
        from using                      2,360  (_merge==2)

    matched                           129,256  (_merge==3)
    -----------------------------------------

. drop _merge 

. save "$path2/2007_data",replace 
(note: file /Users/Wei/Dropbox/Fertility/Workingdata/2007_data.dta not found)
file /Users/Wei/Dropbox/Fertility/Workingdata/2007_data.dta saved

. cap erase "$path2/2007_data_1.dta"

. 
. 
. 
. use "$path1/2008p",clear 

. keep hcode dcode prov pnum  a*

. 
. replace a7 = (2008-int(a7/100))
(154,400 real changes made)

. gen year = 2008 

. save "$path2/2008_data_1",replace 
(note: file /Users/Wei/Dropbox/Fertility/Workingdata/2008_data_1.dta not found)
file /Users/Wei/Dropbox/Fertility/Workingdata/2008_data_1.dta saved

. 
. use "$path1/2008h",clear 

. keep dcode hcode qs d*  e* f? f?? f???  b*

. merge 1:m dcode hcode using "$path2/2008_data_1"

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                           154,400  (_merge==3)
    -----------------------------------------

. drop _merge 

. save "$path2/2008_data",replace 
(note: file /Users/Wei/Dropbox/Fertility/Workingdata/2008_data.dta not found)
file /Users/Wei/Dropbox/Fertility/Workingdata/2008_data.dta saved

. cap erase "$path2/2008_data_1.dta"

. 
. 
. use "$path1/2009p",clear 

. keep hcode dcode prov pnum  a*

. 
. replace a7 = (2009-int(a7/100))
(146,205 real changes made)

. 
. gen year = 2009

. save "$path2/2009_data_1",replace 
(note: file /Users/Wei/Dropbox/Fertility/Workingdata/2009_data_1.dta not found)
file /Users/Wei/Dropbox/Fertility/Workingdata/2009_data_1.dta saved

. 
. use "$path1/2009h",clear 

. keep dcode hcode qs d*  e* f? f?? f???  b*

. merge 1:m dcode hcode using "$path2/2009_data_1"

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                           146,205  (_merge==3)
    -----------------------------------------

. drop _merge 

. save "$path2/2009_data",replace 
(note: file /Users/Wei/Dropbox/Fertility/Workingdata/2009_data.dta not found)
file /Users/Wei/Dropbox/Fertility/Workingdata/2009_data.dta saved

. cap erase "$path2/2009_data_1.dta"

. 
. 
. 
. use "$path2/2002_data", clear 

. append using "$path2/2003_data", nonotes

. append using "$path2/2004_data", nonotes
(note: variable hcode was int, now long to accommodate using data's values)

. append using "$path2/2005_data", nonotes

. append using "$path2/2006_data", nonotes
(note: variable b03 was float, now double to accommodate using data's values)
(note: variable b05 was float, now double to accommodate using data's values)
(note: variable b272 was float, now double to accommodate using data's values)
(note: variable b28 was float, now double to accommodate using data's values)
(note: variable b29 was float, now double to accommodate using data's values)
(note: variable b210 was float, now double to accommodate using data's values)
(note: variable b212 was float, now double to accommodate using data's values)
(note: variable b2120 was float, now double to accommodate using data's values)
(note: variable d91 was float, now double to accommodate using data's values)
(note: variable d92 was float, now double to accommodate using data's values)
(note: variable d920 was float, now double to accommodate using data's values)
(note: variable d921 was float, now double to accommodate using data's values)
(note: variable d9211 was float, now double to accommodate using data's values)
(note: variable d9212 was float, now double to accommodate using data's values)
(note: variable d922 was float, now double to accommodate using data's values)
(note: variable d923 was float, now double to accommodate using data's values)
(note: variable d9232 was float, now double to accommodate using data's values)
(note: variable d9234 was float, now double to accommodate using data's values)
(note: variable d9235 was float, now double to accommodate using data's values)
(note: variable d9236 was float, now double to accommodate using data's values)
(note: variable d9237 was float, now double to accommodate using data's values)
(note: variable d924 was float, now double to accommodate using data's values)
(note: variable d9241 was float, now double to accommodate using data's values)
(note: variable d9244 was float, now double to accommodate using data's values)
(note: variable d9246 was float, now double to accommodate using data's values)
(note: variable d9247 was float, now double to accommodate using data's values)
(note: variable d9249 was float, now double to accommodate using data's values)
(note: variable d92411 was float, now double to accommodate using data's values)
(note: variable d93 was float, now double to accommodate using data's values)
(note: variable d931 was float, now double to accommodate using data's values)
(note: variable d94 was float, now double to accommodate using data's values)
(note: variable d941 was float, now double to accommodate using data's values)
(note: variable d942 was float, now double to accommodate using data's values)
(note: variable d943 was float, now double to accommodate using data's values)
(note: variable d945 was float, now double to accommodate using data's values)
(note: variable d946 was float, now double to accommodate using data's values)
(note: variable d947 was float, now double to accommodate using data's values)
(note: variable d948 was float, now double to accommodate using data's values)
(note: variable d949 was float, now double to accommodate using data's values)
(note: variable d9410 was float, now double to accommodate using data's values)
(note: variable d9411 was float, now double to accommodate using data's values)
(note: variable d95 was float, now double to accommodate using data's values)
(note: variable d951 was float, now double to accommodate using data's values)
(note: variable d9510 was float, now double to accommodate using data's values)
(note: variable d9511 was float, now double to accommodate using data's values)
(note: variable d9513 was float, now double to accommodate using data's values)
(note: variable d9514 was float, now double to accommodate using data's values)
(note: variable d9515 was float, now double to accommodate using data's values)
(note: variable d9516 was float, now double to accommodate using data's values)
(note: variable d9517 was float, now double to accommodate using data's values)
(note: variable d952 was float, now double to accommodate using data's values)
(note: variable d9521 was float, now double to accommodate using data's values)
(note: variable d9522 was float, now double to accommodate using data's values)
(note: variable d953 was float, now double to accommodate using data's values)
(note: variable d9532 was float, now double to accommodate using data's values)
(note: variable d9534 was float, now double to accommodate using data's values)
(note: variable d95340 was float, now double to accommodate using data's values)
(note: variable d96 was float, now double to accommodate using data's values)
(note: variable d961 was float, now double to accommodate using data's values)
(note: variable d962 was float, now double to accommodate using data's values)
(note: variable d963 was float, now double to accommodate using data's values)
(note: variable d965 was float, now double to accommodate using data's values)
(note: variable d966 was float, now double to accommodate using data's values)
(note: variable d967 was float, now double to accommodate using data's values)
(note: variable d968 was float, now double to accommodate using data's values)
(note: variable d9610 was float, now double to accommodate using data's values)
(note: variable d9611 was float, now double to accommodate using data's values)
(note: variable d97 was float, now double to accommodate using data's values)
(note: variable e was float, now double to accommodate using data's values)
(note: variable e0 was float, now double to accommodate using data's values)
(note: variable e1 was float, now double to accommodate using data's values)
(note: variable e19 was float, now double to accommodate using data's values)
(note: variable e192 was float, now double to accommodate using data's values)
(note: variable e1922 was float, now double to accommodate using data's values)
(note: variable f3 was float, now double to accommodate using data's values)
(note: variable f4 was float, now double to accommodate using data's values)
(note: variable f43 was float, now double to accommodate using data's values)
(note: variable f45 was float, now double to accommodate using data's values)
(note: variable f5 was float, now double to accommodate using data's values)
(note: variable f51 was float, now double to accommodate using data's values)
(note: variable f511 was float, now double to accommodate using data's values)
(note: variable f6 was float, now double to accommodate using data's values)
(note: variable f63 was float, now double to accommodate using data's values)
(note: variable f632 was float, now double to accommodate using data's values)
(note: variable f7 was float, now double to accommodate using data's values)
(note: variable f71 was float, now double to accommodate using data's values)
(note: variable f713 was float, now double to accommodate using data's values)
(note: variable a15 was float, now double to accommodate using data's values)
(note: variable a151 was float, now double to accommodate using data's values)
(note: variable a1511 was float, now double to accommodate using data's values)
(note: variable a1512 was float, now double to accommodate using data's values)
(note: variable a152 was float, now double to accommodate using data's values)
(note: variable a153 was float, now double to accommodate using data's values)
(note: variable a1532 was float, now double to accommodate using data's values)
(note: variable a1534 was float, now double to accommodate using data's values)
(note: variable a1535 was float, now double to accommodate using data's values)
(note: variable a1537 was float, now double to accommodate using data's values)
(note: variable a154 was float, now double to accommodate using data's values)
(note: variable a1544 was float, now double to accommodate using data's values)
(note: variable a1546 was float, now double to accommodate using data's values)
(note: variable a1547 was float, now double to accommodate using data's values)
(note: variable a1549 was float, now double to accommodate using data's values)
(note: variable a15411 was float, now double to accommodate using data's values)

. append using "$path2/2007_data", nonotes
(note: variable d9243 was float, now double to accommodate using data's values)
(note: variable d932 was float, now double to accommodate using data's values)
(note: variable d9531 was float, now double to accommodate using data's values)
(note: variable d9536 was float, now double to accommodate using data's values)
(note: variable d954 was float, now double to accommodate using data's values)
(note: variable d9542 was float, now double to accommodate using data's values)
(note: variable d969 was float, now double to accommodate using data's values)
(note: variable e12 was float, now double to accommodate using data's values)
(note: variable e121_2 was float, now double to accommodate using data's values)
(note: variable f31 was float, now double to accommodate using data's values)
(note: variable f311 was float, now double to accommodate using data's values)
(note: variable f62 was float, now double to accommodate using data's values)
(note: variable f623 was float, now double to accommodate using data's values)
(note: variable a1536 was float, now double to accommodate using data's values)
(note: variable a1541 was float, now double to accommodate using data's values)
(note: variable a1543 was float, now double to accommodate using data's values)
(note: variable a19 was float, now double to accommodate using data's values)
(note: variable a7 was float, now double to accommodate using data's values)

. append using "$path2/2008_data", nonotes
(note: variable d9231 was float, now double to accommodate using data's values)
(note: variable d944 was float, now double to accommodate using data's values)
(note: variable d9541 was float, now double to accommodate using data's values)
(note: variable d955 was float, now double to accommodate using data's values)
(note: variable d964 was float, now double to accommodate using data's values)
(note: variable e15 was float, now double to accommodate using data's values)
(note: variable f42 was float, now double to accommodate using data's values)
(note: variable f513 was float, now double to accommodate using data's values)
(note: variable f631 was float, now double to accommodate using data's values)
(note: variable f714 was float, now double to accommodate using data's values)
(note: variable f8 was float, now double to accommodate using data's values)
(note: variable f82 was float, now double to accommodate using data's values)
(note: variable a1531 was float, now double to accommodate using data's values)
(note: variable a18 was float, now double to accommodate using data's values)

. append using "$path2/2009_data", nonotes
(note: variable b110 was float, now double to accommodate using data's values)
(note: variable b114 was float, now double to accommodate using data's values)
(note: variable b115 was float, now double to accommodate using data's values)
(note: variable b116 was float, now double to accommodate using data's values)
(note: variable b117 was float, now double to accommodate using data's values)
(note: variable b118 was float, now double to accommodate using data's values)
(note: variable b119 was float, now double to accommodate using data's values)
(note: variable b12 was float, now double to accommodate using data's values)
(note: variable b120 was float, now double to accommodate using data's values)
(note: variable b121 was float, now double to accommodate using data's values)
(note: variable b124 was float, now double to accommodate using data's values)
(note: variable b126 was float, now double to accommodate using data's values)
(note: variable b127 was float, now double to accommodate using data's values)
(note: variable b130 was float, now double to accommodate using data's values)
(note: variable b131 was float, now double to accommodate using data's values)
(note: variable b132 was float, now double to accommodate using data's values)
(note: variable b134 was float, now double to accommodate using data's values)
(note: variable b135 was float, now double to accommodate using data's values)
(note: variable b136 was float, now double to accommodate using data's values)
(note: variable b14 was float, now double to accommodate using data's values)
(note: variable b15 was float, now double to accommodate using data's values)
(note: variable b16 was float, now double to accommodate using data's values)
(note: variable b18 was float, now double to accommodate using data's values)
(note: variable b21 was float, now double to accommodate using data's values)
(note: variable b211 was float, now double to accommodate using data's values)
(note: variable b213 was float, now double to accommodate using data's values)
(note: variable b214 was float, now double to accommodate using data's values)
(note: variable b215 was float, now double to accommodate using data's values)
(note: variable b216 was float, now double to accommodate using data's values)
(note: variable b217 was float, now double to accommodate using data's values)
(note: variable b219 was float, now double to accommodate using data's values)
(note: variable b21911 was float, now double to accommodate using data's values)
(note: variable b21912 was float, now double to accommodate using data's values)
(note: variable b21921 was float, now double to accommodate using data's values)
(note: variable b21922 was float, now double to accommodate using data's values)
(note: variable b21931 was float, now double to accommodate using data's values)
(note: variable b21932 was float, now double to accommodate using data's values)
(note: variable b22 was float, now double to accommodate using data's values)
(note: variable b24 was float, now double to accommodate using data's values)
(note: variable b25 was float, now double to accommodate using data's values)
(note: variable b26 was float, now double to accommodate using data's values)
(note: variable b27 was float, now double to accommodate using data's values)
(note: variable b271 was float, now double to accommodate using data's values)
(note: variable b3 was byte, now double to accommodate using data's values)
(note: variable b31 was float, now double to accommodate using data's values)
(note: variable b311 was float, now double to accommodate using data's values)
(note: variable b3111 was float, now double to accommodate using data's values)
(note: variable b31111 was float, now double to accommodate using data's values)
(note: variable b31112 was float, now double to accommodate using data's values)
(note: variable b31113 was float, now double to accommodate using data's values)
(note: variable b31114 was float, now double to accommodate using data's values)
(note: variable b31115 was float, now double to accommodate using data's values)
(note: variable b31116 was float, now double to accommodate using data's values)
(note: variable b31117 was float, now double to accommodate using data's values)
(note: variable b3112 was float, now double to accommodate using data's values)
(note: variable b3113 was float, now double to accommodate using data's values)
(note: variable b312 was float, now double to accommodate using data's values)
(note: variable b33 was float, now double to accommodate using data's values)
(note: variable b34 was float, now double to accommodate using data's values)
(note: variable b35 was float, now double to accommodate using data's values)
(note: variable a1 was float, now double to accommodate using data's values)
(note: variable a10 was float, now double to accommodate using data's values)
(note: variable a12 was float, now double to accommodate using data's values)
(note: variable a13 was float, now double to accommodate using data's values)
(note: variable a14 was float, now double to accommodate using data's values)
(note: variable a2 was float, now double to accommodate using data's values)
(note: variable a3 was float, now double to accommodate using data's values)
(note: variable a4 was float, now double to accommodate using data's values)
(note: variable a5 was float, now double to accommodate using data's values)
(note: variable a6 was float, now double to accommodate using data's values)
(note: variable a8 was float, now double to accommodate using data's values)
(note: variable a9 was float, now double to accommodate using data's values)
(note: variable pnum was float, now double to accommodate using data's values)

. cap erase "$path2/2002_data.dta"

. cap erase "$path2/2003_data.dta"

. cap erase "$path2/2004_data.dta"

. cap erase "$path2/2005_data.dta"

. cap erase "$path2/2006_data.dta"

. cap erase "$path2/2007_data.dta"

. cap erase "$path2/2008_data.dta"

. cap erase "$path2/2009_data.dta"

. 
. gen N_member= b21 
(2,763 missing values generated)

. bysort dcode hcode year: egen temp_N=count(hcode)

. replace N_member = temp_N if N_member==.
(2,763 real changes made)

. replace N_member = temp_N if N_member==0 
(6,307 real changes made)

. 
. gen pcode = int(dcode/100)

. replace pcode=1411 if pcode==1423
(3,947 real changes made)

. replace pcode=5001 if pcode==5002
(1,468 real changes made)

. replace pcode=5306 if pcode==5321
(1,132 real changes made)

. replace pcode=5308 if pcode==5327
(944 real changes made)

. replace pcode=5307 if pcode==5332
(1,122 real changes made)

. replace pcode=6209 if pcode==6221
(1,944 real changes made)

. replace pcode=6211 if pcode==6224
(1,033 real changes made)

. replace pcode=6208 if pcode==6227
(1,983 real changes made)

. replace pcode=6210 if pcode==6228
(1,084 real changes made)

. gen age = a7
(401 missing values generated)

. g age2 = age^2/100
(401 missing values generated)

. cap drop educ

. recode a8 (1/2=3)(5/6 = 5) (7/8=6),gen(educ)
(277478 differences between a8 and educ)

. 
. replace a12 = 99 if mi(a12) | a12 ==0 | a12 == 15
(359,170 real changes made)

. gen work_cond = a12 if year >= 2007
(621,471 missing values generated)

. replace work_cond = a12 if a12 <=7 & year < 2007 
(237,666 real changes made)

. replace work_cond = 8 if a12 ==13 & year < 2007 
(43,049 real changes made)

. replace work_cond = 9 if a12 ==10 & year < 2007 
(11,951 real changes made)

. replace work_cond = 10 if a12 ==8 & year < 2007 
(80,939 real changes made)

. replace work_cond = 11 if a12 ==9 & year < 2007 
(2,032 real changes made)

. replace work_cond = 12 if a12 ==12 & year < 2007 
(969 real changes made)

. replace work_cond = 13 if a12 ==11 & year < 2007 
(21,310 real changes made)

. replace work_cond = 15 if a12 ==15 & year < 2007 
(0 real changes made)

. drop if work_cond == 8 
(87,521 observations deleted)

. 
. replace a13 = 99 if a13 == 0
(560,569 real changes made)

. replace a14 = 99 if mi(a14) | a14==0
(560,971 real changes made)

. replace a14 = 8 if a14  ==7 & year >= 2007 
(734 real changes made)

. replace a14 = 4 if a14 == 5 & year < 2007 
(31,951 real changes made)

. replace a14 = a14 -1 if a14 >= 5 & a14 <=7 & year < 2007 
(56,752 real changes made)

. 
. 
. gen occup = a14  

. 
. 
. 
. merge m:1 year using "$path2/cpi", nogen keep(3)

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                           966,171  
    -----------------------------------------

. drop if a1 == 99 | a1 == 0 
(264,250 observations deleted)

. drop if age > 100
(45 observations deleted)

. gen older = age > 60 

. gen young = age < 18 

. 
. gen married = a9 == 2 

. 
. gen head1 = a1 == 1 

. gen head2 = a2 == 1 

. gen sex = a6 

. 
. gen women = sex == 2 

. gen men = sex == 1 

. gen han = a5 == 1 

. 
. egen old_prop = mean(old), by(dcode hcode year)

. egen young_prop = mean(young), by(dcode hcode year)

. egen female_prop = mean(women), by(dcode hcode year)

. egen han_p = mean(han), by(hcode dcode year)

. 
. bys year: su N_member men han age educ married head1 work_cond occup

--------------------------------------------------------------------------------------------------------
-> year = 2002

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    N_member |     72,201    3.229346    .9042318          1          9
         men |     72,201    .4933588    .4999594          0          1
         han |     72,201    .9665379    .1798412          0          1
         age |     72,201    40.38779    17.98051          0        100
        educ |     72,201     4.41505    1.322495          0          9
-------------+---------------------------------------------------------
     married |     72,201    .7411116    .4380272          0          1
       head1 |     72,201    .3641085    .4811826          0          1
   work_cond |     60,249    4.675264    4.259904          1         13
       occup |     72,201    44.70596    47.21168          1         99

--------------------------------------------------------------------------------------------------------
-> year = 2003

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    N_member |     82,435    3.229162    .9313603          1          9
         men |     82,435    .4921211     .499941          0          1
         han |     82,435    .9676594    .1769042          0          1
         age |     82,435    40.64807    18.04653          0         99
        educ |     82,435    4.419676    1.329112          0          9
-------------+---------------------------------------------------------
     married |     82,435    .7419057    .4375888          0          1
       head1 |     82,435    .3636926    .4810646          0          1
   work_cond |     69,006    4.837579    4.260419          1         13
       occup |     82,435    45.06239    47.26967          1         99

--------------------------------------------------------------------------------------------------------
-> year = 2004

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    N_member |     86,238    3.165577    .8948493          1          9
         men |     86,238    .4929266    .4999529          0          1
         han |     86,238    .9682043    .1754569          0          1
         age |     86,238    41.43836    17.91312          0        100
        educ |     86,238     4.47631     1.31198          0          9
-------------+---------------------------------------------------------
     married |     86,238    .7503189    .4328309          0          1
       head1 |     86,238      .36906     .482553          0          1
   work_cond |     72,930    4.904059    4.234987          1         13
       occup |     86,238    44.72276    47.25849          1         99

--------------------------------------------------------------------------------------------------------
-> year = 2005

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    N_member |     89,923    3.142611    .9165921          1         15
         men |     89,923    .4942896    .4999702          0          1
         han |     89,923    .9672386    .1780124          0          1
         age |     89,923    41.53666    18.09271          0         98
        educ |     89,922    4.476391    1.358996          0          9
-------------+---------------------------------------------------------
     married |     89,923    .7534113    .4310276          0          1
       head1 |     89,923    .3709618    .4830649          0          1
   work_cond |     76,417    5.124292    4.187858          1         13
       occup |     89,923     45.8192    47.39985          1         99

--------------------------------------------------------------------------------------------------------
-> year = 2006

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    N_member |     88,853    3.112264     .898655          1          8
         men |     88,853    .4933092     .499958          0          1
         han |     88,853    .9686223    .1743372          0          1
         age |     88,853    42.19793    17.89309          0         99
        educ |     88,853    4.537292    1.337802          0          9
-------------+---------------------------------------------------------
     married |     88,853    .7618088    .4259791          0          1
       head1 |     88,853    .3763407    .4844698          0          1
   work_cond |     76,260    5.054524    4.138315          1         13
       occup |     88,853     44.5595    47.25542          1         99

--------------------------------------------------------------------------------------------------------
-> year = 2007

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    N_member |     86,250    3.083884    .9282613          1         10
         men |     86,250    .4913739    .4999285          0          1
         han |     86,250    .9680696    .1758159          0          1
         age |     86,250    44.57539    16.05305          0         99
        educ |     86,250    4.678713    1.364569          0          9
-------------+---------------------------------------------------------
     married |     86,250    .8304464    .3752424          0          1
       head1 |     86,250    .4088464    .4916237          0          1
   work_cond |     86,250    12.38074    25.67107          1         99
       occup |     86,250     39.1322    46.07473          1         99

--------------------------------------------------------------------------------------------------------
-> year = 2008

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    N_member |    100,827    3.101173    .9855085          1          9
         men |    100,827    .4909003    .4999197          0          1
         han |    100,827    .9716941    .1658462          0          1
         age |    100,827    43.15439    17.67037          0        100
        educ |    100,827     4.52967    1.473999          0          9
-------------+---------------------------------------------------------
     married |    100,827    .7895207    .4076511          0          1
       head1 |    100,827    .3926627    .4883452          0          1
   work_cond |    100,827    16.42435    30.46034          1         99
       occup |    100,827    43.94354    47.07692          1         99

--------------------------------------------------------------------------------------------------------
-> year = 2009

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    N_member |     95,149    3.090269    .9748793          1          8
         men |     95,149    .4914713    .4999299          0          1
         han |     95,149    .9703938    .1694992          0          1
         age |     95,149     43.7221     17.4873          0         99
        educ |     95,149    4.572439    1.446623          0          9
-------------+---------------------------------------------------------
     married |     95,149    .7961303    .4028754          0          1
       head1 |     95,149    .3940661    .4886517          0          1
   work_cond |     95,149    16.21219    30.25612          1         99
       occup |     95,149    43.43296    47.00045          1         99


. 
. keep if age >= 25  
(101,394 observations deleted)

. 
. gen year_birth = year - age 

. *keep if year_birth <= 1979
. 
. 
. gen lninc = ln(d92/cpi)
(1,364 missing values generated)

. gen lninc_per = ln((d92/cpi)/N_member)
(1,364 missing values generated)

. 
. * Income **
. gen labor_share = d921/d92 if  d921/d92<2
(1,364 missing values generated)

. gen run_share = d922/d92 if  d922/d92<2
(1,364 missing values generated)

. gen wealth_in_share = d923/d92 if  d923/d92<2
(1,364 missing values generated)

. gen trans_in_share = d924/d92 if  d924/d92<2
(1,364 missing values generated)

. 
. 
. gen lnexp = ln(d95/cpi)
(1,360 missing values generated)

. gen lnexp_per = ln((d95/cpi)/N_member)
(1,360 missing values generated)

. 
. ***** Shares in expenditure ***
. gen cons_share = d951/d95 if d951/d95 <= 2
(1,360 missing values generated)

. gen wealth_share = d954/d95 if d954/d95 <= 2
(1,360 missing values generated)

. gen trans_out_share = d953/d95 if d953/d95 <= 2
(1,360 missing values generated)

. gen so_ins_share = d955/d95 if d955/d95  <= 2
(1,360 missing values generated)

. gen estate_share = d952/d95 if d952/d95  <= 2
(1,360 missing values generated)

. 
. gen lnconsump = ln(e/cpi)
(1,360 missing values generated)

. gen lnconsump_per = ln((e/cpi)/N_member)
(1,360 missing values generated)

. gen lnfood = ln(e1)
(1,360 missing values generated)

. gen lnfood_per = ln(e1/N_member)
(1,360 missing values generated)

. drop if educ == 9 | mi(educ) | educ == 0
(3,312 observations deleted)

. 
. **** Consumption shares ****
. gen food_share = e1/e if e1/e<=2
(1,358 missing values generated)

. gen cloth_share = f2/e if f2/e <=2
(1,358 missing values generated)

. gen long_share = f3/e if f3/e <=2 
(1,358 missing values generated)

. gen med_share = f4/e if f4/e <=2 
(1,358 missing values generated)

. gen trans_comm_share = f5/e if f5/e <=2
(1,358 missing values generated)

. gen edu_ent_share = f6/e if f6/e <=2
(1,358 missing values generated)

. gen house_share = f7/e if f7/e <=2
(1,358 missing values generated)

. gen other_share = f8/e if f8/e <=2
(1,358 missing values generated)

. gen service_share = e0/e if e0/e <=2
(1,358 missing values generated)

. 
. **** Consumption detailed shares ****
. gen grain_share = e11/e if e11/e1 <=2
(1,358 missing values generated)

. gen meat_share = (e12+e17)/e if (e12+e17)/e1<=2
(1,358 missing values generated)

. gen veg_share = (e13+e16)/e if (e13+e16)/e1<=2
(1,358 missing values generated)

. gen sug_share = e151/e if e151/e1<=2
(1,358 missing values generated)

. gen smoke_share = e152/e if e152/e1<=2
(1,358 missing values generated)

. gen wine_share = e153_2/e if e153_2/e1<=2
(1,358 missing values generated)

. gen drink_share = e154/e if e152/e1<=2
(1,358 missing values generated)

. gen resturant_share = e19/e if e19/e1<=2
(1,358 missing values generated)

. 
. **** Long term details ***
. gen durable_share = (f31+f32+f33+f34+f35)/e if (f31+f32+f33+f34+f35)/e < 2
(1,358 missing values generated)

. gen housekeep_share = f36/e if f36/e < 2
(1,358 missing values generated)

. 
. **** Medical details ***
. gen equi_med_share = (f41+f42)/e if  (f41+f42)/e <2 
(1,358 missing values generated)

. gen drug_med_share = (f43)/e if  (f43)/e <2 
(1,358 missing values generated)

. gen medicare_med_share = (f45)/e if  (f45)/e <2 
(1,358 missing values generated)

. 
. **** Transportation & Communication details ***
. gen transportation_share = f51/e if f51/e<2
(1,358 missing values generated)

. gen communication_share = f52/e if f52/e<2
(1,358 missing values generated)

. 
. 
. **** Education & Entertainment details ***
. gen enter_share = (f61+f62)/e if f61/e<2
(1,358 missing values generated)

. gen enter_real_share = f61/e if f61/e<2
(1,358 missing values generated)

. gen enter_serv_share = f62/e if f62/e<2
(1,358 missing values generated)

. gen edu_share = f63/e if f63/e<2
(1,358 missing values generated)

. gen edu_real_share = f631/e if f631/e<2
(1,358 missing values generated)

. gen edu_serv_share = f632/e if f632/e<2
(1,358 missing values generated)

. **** other details ***
. gen other_real_share = f81/e if f81/e < 2 
(1,358 missing values generated)

. gen other_gold_share = (f811)/e if f81/e < 2 
(1,358 missing values generated)

. gen other_beauty_share = (f813+f814)/e if f81/e < 2 
(1,358 missing values generated)

. gen other_serv_share = f82/e if f82/e < 2 
(1,358 missing values generated)

. 
. gen activity_share = trans_comm_share+edu_ent_share
(1,358 missing values generated)

. 
. gen saving = (d92 -e)/d92 *100
(1,362 missing values generated)

. drop if mi(saving)
(1,362 observations deleted)

. drop if year_birth == 0 
(0 observations deleted)

. 
. gen senior = educ >= 5 

. gen college = educ >= 6

. drop if lninc_per == . 
(0 observations deleted)

. gen lnearning_per = ln(d921/N_member/cpi)
(85,006 missing values generated)

. drop if mi(lnearning_per)
(85,006 observations deleted)

. 
. replace qs = 10 if mi(qs)
(0 real changes made)

. replace qs = qs/10 if year == 2009
(70,143 real changes made)

. 
. 
. cap drop *_food_share sug_wine_share

. gen grain_food_share = grain_share/food_share

. gen meat_food_share = meat_share/food_share

. gen veg_food_share = veg_share/food_share

. gen sug_food_share = sug_share/food_share

. gen smoke_food_share = smoke_share/food_share

. gen wine_food_share = wine_share/food_share

. gen sug_wine_share = sug_food_share  + wine_food_share

. gen drink_food_share = (drink_share)/food_share

. gen resturant_food_share = resturant_share/food_share

. 
. gen house_own = b24
(2 missing values generated)

. order prov year year_birth age  han head* qs N_member

. 
. drop  b013-temp_N

. 
. 
. ren year yr_t

. qui:{

. egen fine_birth = rowmean(fine_age0)
(15510 missing values generated)

. egen fine_1_9 = rowmean(fine_age1-fine_age9)
(10302 missing values generated)

. egen fine_10_19 = rowmean(fine_age10-fine_age19)
(11161 missing values generated)

. egen fine_20_25 = rowmean(fine_age20-fine_age25)
(13805 missing values generated)

. 
. *egen fine_f2_5 = rowmean(fine_f2 fine_f1 fine_age0 fine_age1-fine_age5)
. egen fine_6_10 = rowmean(fine_age6-fine_age10)
(13186 missing values generated)

. egen fine_11_15 = rowmean(fine_age11-fine_age15)
(13586 missing values generated)

. egen fine_16_20 = rowmean(fine_age16-fine_age20)
(13986 missing values generated)

. egen fine_21_25 = rowmean(fine_age21-fine_age25)
(14226 missing values generated)

. 
. egen fine_6_12 = rowmean(fine_age6-fine_age12)
(12072 missing values generated)

. egen fine_13_19 = rowmean(fine_age13-fine_age19)
(12856 missing values generated)

. 
. egen fine_6_15 = rowmean(fine_age6-fine_age15)
(10521 missing values generated)

. egen fine_16_25 = rowmean(fine_age16-fine_age25)
(11961 missing values generated)

. 
. 
. drop if mi(fine_10_19)
(11,161 observations deleted)

. ren yr_t year 

. 
. drop if educ == 0 
(0 observations deleted)

. 
. 
. compress
  variable prov was float now byte
  variable year was float now int
  variable year_birth was float now int
  variable age was float now byte
  variable han was float now byte
  variable head1 was float now byte
  variable head2 was float now byte
  variable N_member was float now byte
  variable bdchs was float now byte
  variable bjqhs was float now byte
  variable pcode was float now int
  variable work_cond was float now byte
  variable occup was float now byte
  variable older was float now byte
  variable young was float now byte
  variable married was float now byte
  variable sex was float now byte
  variable women was float now byte
  variable men was float now byte
  variable senior was float now byte
  variable college was float now byte
  variable house_own was float now byte
  variable educ was double now byte
  (36,112,440 bytes saved)

. save "$path2/ocp_uhs_reg",replace 
file /Users/Wei/Dropbox/Fertility/Workingdata/ocp_uhs_reg.dta saved

. 
. log close 
      name:  <unnamed>
       log:  /Users/Wei/Dropbox/Fertility/Results/UHS_data.log
  log type:  text
 closed on:  28 Apr 2020, 11:58:13
--------------------------------------------------------------------------------------------------------
